package com.joyxy.spider.mapscript.operation;

/**
 * 跳跃操作
 * 操作数: 3
 * 参数: LUR/X/Y/Fly
 */
public class JumpOperation extends BaseOperation {
    /** 跳跃方向: 0-左跳, 1-右跳, 2-上跳并爬绳子, 3-按空格键 */
    private int direction;
    /** 跳跃点横坐标 */
    private int jumpX;
    /** 跳跃点纵坐标 */
    private int jumpY;
    /** 跳跃过程中按方向键的长短 */
    private int flyDuration;
    
    public JumpOperation(int direction, int jumpX, int jumpY, int flyDuration) {
        super(3, "跳跃");
        this.direction = direction;
        this.jumpX = jumpX;
        this.jumpY = jumpY;
        this.flyDuration = flyDuration;
    }
    
    /**
     * 从参数数组创建跳跃操作
     */
    public static JumpOperation fromParameters(int[] parameters) {
        if (parameters == null || parameters.length < 4) {
            throw new IllegalArgumentException("跳跃操作需要4个参数: LUR/X/Y/Fly");
        }
        return new JumpOperation(parameters[0], parameters[1], parameters[2], parameters[3]);
    }
    
    @Override
    public void execute() {
        String dirDesc = getDirectionDescription();
        System.out.println("执行跳跃: 在坐标(" + jumpX + "," + jumpY + ") " + dirDesc + 
                         ", 持续时间=" + flyDuration);
        // 这里应该调用实际的跳跃逻辑
    }
    
    @Override
    public boolean isValid() {
        return direction >= 0 && direction <= 3 && jumpX >= 0 && jumpY >= 0 && flyDuration >= 0;
    }
    
    @Override
    public String getDetailInfo() {
        return String.format("跳跃: 坐标(%d,%d) %s, 持续时间=%d", 
                jumpX, jumpY, getDirectionDescription(), flyDuration);
    }
    
    /**
     * 获取跳跃方向描述
     */
    public String getDirectionDescription() {
        switch (direction) {
            case 0: return "左跳";
            case 1: return "右跳";
            case 2: return "上跳并爬绳子";
            case 3: return "按空格键";
            default: return "未知方向";
        }
    }
    
    /**
     * 检查是否为特殊跳跃类型
     */
    public boolean isLeftJump() { return direction == 0; }
    public boolean isRightJump() { return direction == 1; }
    public boolean isUpJumpWithRope() { return direction == 2; }
    public boolean isSpaceKeyJump() { return direction == 3; }
    
    // Getter methods
    public int getDirection() { return direction; }
    public int getJumpX() { return jumpX; }
    public int getJumpY() { return jumpY; }
    public int getFlyDuration() { return flyDuration; }
    
    @Override
    public String toString() {
        return String.format("Jump{pos=(%d,%d), dir=%d, duration=%d}", 
                jumpX, jumpY, direction, flyDuration);
    }
} 